package pers.qianyu.diytomcat.http;

import pers.qianyu.diytomcat.catalina.*;

import java.io.*;
import java.util.*;

/**
 * @author mizzle rain
 * @date 2021-01-09 20:27
 */
public class ApplicationContext extends BaseServletContext {
    private Context context;
    private Map<String, Object> attributesMap;

    public ApplicationContext(Context context) {
        this.context = context;
        this.attributesMap = new HashMap<>();
    }

    @Override
    public void removeAttribute(String s) {
        attributesMap.remove(s);
    }

    @Override
    public Object getAttribute(String s) {
        return attributesMap.get(s);
    }

    @Override
    public void setAttribute(String s, Object o) {
        attributesMap.put(s, o);
    }

    @Override
    public Enumeration<String> getAttributeNames() {
        return Collections.enumeration(attributesMap.keySet());
    }

    @Override
    public String getRealPath(String s) {
        return new File(context.getDocBase(), s).getAbsolutePath();
    }
}
